// import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../utils/storage/searchService.dart';
class MySearchController extends GetxController {
  //TODO: Implement SearchController
  String? keywords = "";
  RxList historyList = [].obs;

  // 添加搜索记录
 void addHistoryList(String keywords) async {
       await SearchService.addHistoryData(keywords);
       print("添加搜索记录: $keywords");
 }
  // 获取本地存储的搜索记录
 void getHistoryData() async {
     var tempList = await SearchService.getHistoryData();
     if(tempList.isNotEmpty) {
      historyList.addAll(tempList);
      update(); // 通知UI更新
     }
   
  }
 // 删除单条记录
 void removeHistoryData(String keywords) async{
   await SearchService.removeHistoryData(keywords);
   historyList.remove(keywords);
   update(); // 通知UI更新
 }
// 清空全部记录
void clearHistoryData()  async{
 await SearchService.clearHistoryData();
  historyList.clear();
  update(); // 通知UI更新 
}
  @override
  void onInit() {
    super.onInit();
    getHistoryData();
  }
 
  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }
}
